/** JSONUtils */
package domain.utils;

import java.util.Iterator;

import org.json.JSONObject;

/**
 * Holds utility methods for working with JSON.
 * @author Reid Harrison
 * @version 1.0
 */
public class JSONUtils {
	
	/**
	 * Merges the given JSONObjects into one JSONObject.
	 * @param json1
	 * @param json2
	
	 * @return JSONObject */
	public static JSONObject merge(final JSONObject json1, final JSONObject json2) {
		final JSONObject mergedJson = new JSONObject();
		
		final Iterator it1 = json1.keys();
		final Iterator it2 = json2.keys();
		
		while (it1.hasNext()) {
			String key = (String) it1.next();
			mergedJson.put(key, json1.get(key));
		}
		
		while (it2.hasNext()) {
			String key = (String) it2.next();
			mergedJson.put(key, json2.get(key));
		}
		
		return mergedJson;
	}
	
	/**
	 * Method toString.
	 * @return String
	 */
	public String toString() {
		return super.toString();
	}

}
